layui.use(['form','table','jquery','layer'],function () {
    var $ = layui.jquery;
    var form = layui.form;
    var table = layui.table;
    var layer = layui.layer;

    /* 表格渲染开始 */
    var feedbackType = '';
    var feedbackStatus = '';
    var feedbackTable = table.render({
        elem:"#table",
        url:"/feedback/getAllUserFeedBack?feedbackType="+feedbackType+"&feedbackStatus="+feedbackStatus,
        toolbar:"#tool",
        defaultToolbar: ['','',''],
        page:true,
        limit:7,
        limits:[7,14,21,28],
        cols:[
            [
                {type:'checkbox',align:"center"},
                {type:"numbers",title:"编号",align:"center"},
                {field:"feedbackType",title:"反馈类型",align:"center",templet:function (data) {
                        if(data.feedbackType==2){
                            return "视频反馈";
                        }else if(data.feedbackType==3){
                            return "商品反馈";
                        }else{
                            return "其他反馈";
                        }
                    }},
                {field:"feedbackContent",title:"反馈内容",align:"center"},
                {field:"feedbackStatus",title:"审核状态",align:'center',height:50,templet:function (data) {
                        if(data.feedbackStatus==2){
                            return '已提交';
                        }else if(data.feedbackStatus==3){
                            return "待审核";
                        }else if(data.feedbackStatus==4){
                            return "审核通过"+"<p><a href='javascript:seeFeedback("+data.feedbackId+");'style='color: #2F4056;'>审核详情</a></p>";
                        }else if(data.feedbackStatus==5){
                            return "未提交";
                        }else{
                            return "审核驳回";
                        }
                    }},
                {title:"操作",align:"center",templet:function (data) {
                        if(data.feedbackStatus==4){
                            return "<div>"+
                                "<a href='javascript:delFeebdack("+data.feedbackId+");' style='color: #2F4056;;margin-right: 10px'>删除</a>"
                                +"</div>";
                        }else if(data.feedbackStatus==3){
                            return "<div>"+
                                "<a href='javascript:toExamine(\""+data.feedbackId+"\",\""+data.feedbackStatus+"\",\""+data.feedbackContent+"\",\""+data.feedbackType+"\");' style='color: #2F4056;;margin-right: 10px'>审核</a>"
                                +"<a href='javascript:delFeebdack("+data.feedbackId+");' style='color: #2F4056;;margin-right: 10px'>删除</a>"
                                +"</div>";
                        }else{
                            return  "<div>"+
                                "<a href='javascript:delFeebdack("+data.feedbackId+");' style='color: #2F4056;;margin-right: 10px'>删除</a>"
                                +"</div>";
                        }
                    }}
            ]
        ]
    });
    /* 表格渲染结束 */
    
    
    /*筛选查询开始*/
    form.on("submit(sub)",function (data) {
        var feedbackType = $("#feedbackType").val();
        var feedbackStatus = $("#feedbackStatus").val();
        feedbackTable.reload({
            url:"/feedback/getAllUserFeedBack?feedbackType="+feedbackType+"&feedbackStatus="+feedbackStatus,
        });
        return false;
    })
    /*筛选查询结束*/

    /* 重置开始 */
    form.on('submit(subs)',function (data) {
        feedbackTable.reload({
            url:"/feedback/getAllUserFeedBack?feedbackType="+feedbackType+"&feedbackStatus="+feedbackStatus,
        });
    });
    /* 重置结束 */

    /* 删除开始 */
    delFeebdack = function delFeebdack(feedbackId){
        layer.confirm('是否确定拦截此优惠卷', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                url:"/feedback/delFeebdack",
                data:{"feedbackId":feedbackId},
                dataType:"json",
                Type:"post",
                success:function () {
                    location.reload();
                }
            });
        });
    }
    /* 删除结束 */

    /* 审核开始 */

    /* 审核结束 */
    toExamine = function toExamine(feedbackId,feedbackStatus,feedbackContent,feedbackType){
        if(feedbackType==2){
            feedbackType =  "视频反馈";
        }else if(feedbackType==3){
            feedbackType = "商品反馈";
        }else{
            feedbackType = "其他反馈";
        }
        layer.open({
            type:2,
            shode:0,
            maxmin:true,
            title:"反馈审核",
            content:"/feedback/feedback-toExamine.html",
            area:['460px','390px'],
            success:function (layero,index) {
                obj = layero.find("iframe").contents();
                obj.find("#feedbackType").text(feedbackType);
                obj.find("#feedbackId").val(feedbackId);
                obj.find("#feedbackContent").text(feedbackContent);
            }
        });
    }
    /* 审核详情 */
    seeFeedback = function seeFeedback(feedbackId){
        $.ajax({
            url:"/feedback/seeFeedback",
            data:{"feedbackId":feedbackId},
            dataType:"json",
            Type:"post",
            success:function(data){
                see(data);
            }
        });
    };
    function see(data){
        layer.open({
            type:2,
            shode:0,
            maxmin:true,
            title:"审核详情",
            content:"/feedback/feedback-see.html",
            area:['600px', '540px'],
            btn:["确定"],
            yes:function(index){
                layer.close(index);
            },
            success:function (layero,index) {
                var obj = layero.find("iframe").contents();
                obj.find("input[name=feedbackId]").val(data.data.feedbackId);
                var feedbackType = data.data.feedbackType;
                if(feedbackType==2){
                    feedbackType =  "视频反馈";
                }else if(feedbackType==3){
                    feedbackType = "商品反馈";
                }else{
                    feedbackType = "其他反馈";
                }
                obj.find("input[name=feedbackType]").val(feedbackType);
                obj.find("input[name=feedbackContent]").val(data.data.feedbackContent);
                obj.find("input[name=createDate]").val(data.data.createDate);
                var feedbackStatus = data.data.feedbackStatus;
                if(feedbackStatus == 2){
                    feedbackStatus =  '已提交';
                }else if(feedbackStatus == 3){
                    feedbackStatus =  "待审核";
                }else if(feedbackStatus == 4){
                    feedbackStatus = "审核通过";
                }else if(feedbackStatus == 5){
                    feedbackStatus = "未提交";
                }else{
                    feedbackStatus = "审核驳回";
                }
                obj.find("input[name=feedbackStatus]").val(feedbackStatus);
                obj.find("input[name=trueName]").val(data.data.trueName);
                obj.find("input[name=updateDate]").val(data.data.updateDate);
            }
        });
    }
    /* 审核详情 */


    /* 返回开始 */
    goBack = function goBack() {
        //通过页面查找iframe
        parent.$('#Jump').val('首页');
        parent.getQuick();
        return;
    }
    /* 返回结束 */

    /* 刷新开始 */
    Refresh = function Refresh() {
        location.reload();
    };
    /* 刷新结束 */
});